<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/main.js"></script>
    <script src="js/industry-proxy-app.js"></script>
    <link href="js/app.plugin.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="main">
    <div class="header">
        <div class="headerL">
            <img src="images/u7.png">
            <div class="name">
                <p class="name1">
                    山东大学附属儿童医院
                </p>
                <p class="des">
                    Childern’s Hospital Affiliated to Shandong Universitry
                </p>
            </div>
        </div>
        <div class="headerR">
            <span id="kyear"></span>
            <span id="ktime"></span>
        </div>
    </div>
    <div class="con">
        <div class="title">
            <a class="goBack">返回</a>
            <span id="timeOut"></span>
        </div>
        <div class="daying">
            <p>
                <img src="images/u155.png">
            </p>
            <h2>
                打印中 , 请稍后 ….
            </h2>
        </div>
        <div class="window" style="display: none">
            <div class="success">
                <h2 id="titleWindow">
                    打印成功
                </h2>
                <p id="messageWindow">
                    打印成功 , 请及时取走票据
                </p>
                <a class="goIndex">
                    <img src="images/pcg.png">
                </a>
            </div>
        </div>
    </div>
    <div class="footer">
        <img src="images/u29.svg">
        0531-87964999
    </div>
</div>

</body>
<script>
    var fapiaoInfo ;
    $(function () {
        daojishi()
         fapiaoInfo = JSON.parse(localStorage.getItem('fapiaoDataInfo'));
        printElectBillSet(fapiaoInfo.billBatchCode, fapiaoInfo.billNo, fapiaoInfo.random)
    })

    //1、本级单位应用接入（单个单位使用）
    var industry = new BsIndustryApi({
        'appId': 'JNSETYY6081679',
        'appKey': '8665408f4fe43f9c871b0b0da0',
        'type': 'medical',
        'url': 'https://dxx.gylxpsy.com:10023/medical-web'
    });    //2、直管单位创建的应用接入下级单位（多个单位使用）
    //    var industry = new BsIndustryApi({'region':'region',
    //        'deptcode':'deptcode',
    //        'appId':'GDYLCSDW07303568044',
    //        'appKey':'c45dc642471b1aa1cbcc7aef48',
    //        'type':'medical',
    //        'url':'http://localhost:8080/medical-web'});

    /**
     * 打印纸质财政票，可设置是否预览
     * @param {String} pBillBatchCode 纸质票据代码
     * @param {String} pBillNo        纸质票据号码
     * @param {String} pBillCode      纸质票据种类编码（打印设置中设置的编码）
     * @memo  先通过后台服务调用换开接口turnPaper或者重新换开接口reTurnPaper，然后根据返回的结果调用js打印组件
     */
    function printPaperBillSet() {
        var param = {
            'pBillBatchCode': '102110119',
            'pBillNo': '',
            'pBillCode': '1021101'
        }
        industry.printPaperBill(param, '1.0', false).then(function (data) {
            if (data && data.result != 'S0000') {
                alert(data.message)
            }
            console.log("success")
        }).fail(function (data) {
            console.log(data)
        });
    }

    /**
     * 打印电子票据(打印A4)，可按照票种设置打印机
     * @param {String} billBatchCode  电子票据批次代码
     * @param {String} billNo         电子票据号码
     * @param {String} random         电子票据校验码
     * @param {String} moduleId       票据种类编码（打印设置中设置的编码）
     */
    function printElectBillSet(billBatchCode, billNo, random) {
        var param = {
            'billBatchCode': billBatchCode,
            'billNo': billNo,
            'random': random,
            'moduleId': '000000001'
        }
        industry.printElectBill(param, '1.0', false).then(function (data) {

            if (data && data.result != 'S0000') {
                $("#titleWindow").html('打印失败');
                $("#messageWindow").html(data.message);
                $(".window").show()
            }else{
                $("#titleWindow").html('打印成功');
                $("#messageWindow").html('打印成功 , 请及时取走票据');
                $(".window").show()
                $.ajax({
                    url: domain + "/web/api/machine/printFaPiao",
                    type: "post",
                    dataType: "json",
                    data: {'id': fapiaoInfo.id},
                    success: function (data, textStatus, jqxhr) {

                    },
                    error: function (jqxhr, textStatus, error) {
                        alert('请求失败！')
                    }
                })
                setTimeout(function () {
                    $(".window").hide();
                    window.location.href = 'index.html';
                }, 5000)
            }
            console.log(data)
            console.log("success")
        }).fail(function (data) {
            $("#titleWindow").html('打印失败');
            $("#messageWindow").html('请联系管理员');
            $(".window").show()
            console.log(data)
        });
    }

    /**
     * 打印电子票据清单(PDF)，可按照模板设置打印机
     * @param {String} billBatchCode  电子票据批次代码
     * @param {String} billNo         电子票据号码
     * @param {String} random         电子票据校验码
     * @param {String} total          总页数（通过后台接口服务调用4.5.5获取电子票据清单总页数接口）
     * @param {String} pageNoBgn      起始页码
     * @param {String} pageNoEnd      终止页码
     * @param {String} moduleId       清单模板（打印设置中设置的编码）
     */
    function printElectBillList() {
        var param = {
            'billBatchCode': '44811819',
            'billNo': '0000022427',
            'random': 'b1273e1',
            'total': '3',
            'pageNoBgn': '1',
            'pageNoEnd': '1',
            'moduleId': '00000000'
        }
        industry.printElectBillList(param, '1.0', false).then(function (data) {
            if (data && data.result != 'S0000') {
                alert(data.message)
            }
            console.log("success")
        }).fail(function (data) {
            console.log(data)
        });
    }

    /**
     * 设置打印机(可按照票种设置)
     * @param {String} moduleId  票据种类编码或者清单模板（可自定义）
     */
    function printerSet() {
        industry.printerSet('060101').then(function (data) {
            console.log("success")
        }).fail(function (data) {
            console.log(data)
        });
    }

    /**
     * pos刷卡缴款
     */
    function doPos() {
        var param = {
            'payCode': '35000019666000001718',
            'amt': '0.01',
            'bankCode': '0001'
        }
        industry.doPos(param).then(function (data) {
            if (data == 'S0000') {
                console.log("SUCCESS");
            } else {
                console.log("FAIL:" + data);
            }
        }).fail(function (data) {
            console.log("ERROR:" + data)
        });
    }

    /**
     * 打印电子缴款书
     */
    function printPaybook() {
        var param = {
            'payCode': '50000019161000000140'
        }
        industry.printPaybook(param, '1.0', true).then(function (data) {
            if (data && data.result != 'S0000') {
                alert(data.message)
            }
            console.log("success")
        }).fail(function (data) {
            console.log(data)
        });
    }

    function caSignInvoice() {
        var param =
            {
                'busNo': '20210812007',
                'busType': '02',
                'payerType': '1',
                'payer': 'js开票',
                'busDateTime': '20210812143237097',
                'placeCode': '002',
                'payee': '李四',
                'payeeCode': 'sf001',
                'author': '李四',
                'checker': '复核人',
                'ICD': '1123',
                'totalAmt': 300,
                'medCareInstitution': '123456',
                'selfPayAmt': 2.22,
                'selfCashPay': 10,
                'remark': '备注信息一',
                'alipayCode': 'huqi2888@163.com',
                'weChatOrderNo': '565241xs',
                'weChatMedTransNo': '565241',
                'isArrears': '1',
                'arrearsReason': '违规操作',
                'openID': '123488xss',
                'tel': '11460140936',
                'email': '12312341284@qq.com',
                'idCardType': '1101',
                'idCardNo': '350426199609252520',
                'cardType': '1102',
                'cardNo': '362524198800000000',
                'medicalInstitution': '三甲医院',
                'medicalCareType': '公务员报销',
                'medCareTypeCode': '01',
                'medicalInsuranceID': '007007007007',
                'medCareAreaCode': '350002',
                'consultationDate': '20210809',
                'patientCategory': '内科',
                'patientCategoryCode': '1',
                'patientNo': '001',
                'patientId': '01',
                'sex': '男',
                'age': '23',
                'caseNumber': '100001',
                'specialDiseasesName': '',
                'accountPay': 30,
                'fundPay': 30,
                'otherfundPay': 30,
                'ownPay': 1.4,
                'cashPay': 2.2,
                'chequePay': 2.2,
                'transferAccountPay': 2.3,
                'cashRecharge': 2.4,
                'chequeRecharge': 2.5,
                'transferRecharge': 2.6,
                'cashRefund': 2.1,
                'chequeRefund': 1.1,
                'transferRefund': 1.3,
                'reimbursementAmt': 1.2,
                'balancedNumber': '0',
                'selfPayTwo': 1.1,
                'startPay': 1.1,
                'medRangePay': 1.2,
                'addMedrangePay': 1.2,
                'ownAcBalance': 2.5,
                'seriousIllnessInsurancePay': 14.12,
                'medicalRescuePay': 14.13,
                'elseInsurancePay': 14.14,
                'paymentMethod': '现金',
                'addYearOutpatientPay': 2.4,
                'addYearMedOutpatientPay': 2.4,
                'civilServantPay': 2.3,
                'selfConceitedAmt': 1.1,
                'clearState': '',
                'eBillRelateNo': '0',
                'chargeDetail': [{
                    'sortNo': 1,
                    'chargeCode': '2990001603',
                    'chargeName': '西药费',
                    'unit': '元',
                    'std': 100,
                    'number': 1,
                    'amt': 100,
                    'selfAmt': 1.11,
                    'remark': '备注信息'
                }, {
                    'sortNo': 1,
                    'chargeCode': '2990001602',
                    'chargeName': '检查费',
                    'unit': '元',
                    'std': 100,
                    'number': 1,
                    'amt': 100,
                    'selfAmt': 1.11,
                    'remark': '备注信息'
                }, {
                    'sortNo': 1,
                    'chargeCode': '2990001601',
                    'chargeName': '诊查费',
                    'unit': '元',
                    'std': 100,
                    'number': 1,
                    'amt': 100,
                    'selfAmt': 1.11,
                    'remark': '备注信息'
                }],
                'listDetail': [{
                    'listDetailNo': '000110001',
                    'chargeCode': '2990001603',
                    'chargeName': '西药费',
                    'prescribeCode': '1001',
                    'listTypeCode': '1001',
                    'listTypeName': '抗生素类抗感染药物',
                    'code': '001',
                    'name': '头孢颗粒',
                    'form': '包',
                    'specification': '1包',
                    'unit': '元',
                    'std': 100,
                    'number': 1,
                    'amt': 100,
                    'selfAmt': 2.2,
                    'receivableAmt': 1.2,
                    'medicalCareType': '1',
                    'medCareItemType': '医保项目类型',
                    'medReimburseRate': 0,
                    'remark': '信息',
                    'sortNo': 1,
                    'chrgtype': '自费',
                    'payDate': '20210809',
                    'medCareItemCode': '001002',
                    'medCareItemName': '感冒药'
                }],
                'otherInfo': [{
                    'infoNo': 111111,
                    'infoName': '扩展信息',
                    'infoValue': '信息一'
                }],
                'otherMedicalList': [{
                    'infoNo': 111111,
                    'infoName': '医保信息',
                    'infoValue': '信息一',
                    'infoOther': '其它信息'
                }],
                'payChannelDetail': [{
                    'payChannelCode': '02',
                    'payChannelValue': 300
                }],
                'payOrderInfo': [{
                    'payOrderCode': '9209',
                    'payOrderValue': '招行'
                }]
            }
        industry.caSignInvoice(param, '1.0').done(function (data) {
            console.log(data)
            if (data == undefined || data == null) {
                alert('参数未定义,请检查!');
            } else {
                alert(JSON.stringify(data));
            }

        }).fail(function (data) {
            console.log(data);
        });
    }

    function caSignWriteOff() {
        var param = {
            "billBatchCode": "44811821",
            "billNo": "0030150615",
            "reason": "开错了",
            "operator": "张三",
            "busDateTime": "20210812141029670",
            "createTime": "20210812141029670",
            "billBusDate": "20210812141029670",
            "placeCode": "002"
        }

        industry.caSignWriteOff(param, '1.0').done(function (data) {
            console.log(data)
            if (data == undefined || data == null) {
                alert('参数未定义,请检查!');
            } else {
                alert(JSON.stringify(data));
            }
        }).fail(function (data) {
            console.log(data)
        });
    }


    //已换开冲红
    function caSignWriteOffPBill() {
        var param =
            {
                "billBatchCode": "44812021",
                "billNo": "0011442154",
                "pBillBatchCode": "42811920",
                "pBillNo": "0090008411",
                "reason": "开错了",
                "operator": "詹三",
                "busDateTime": "20210811143415638",
                "placeCode": "002"
            }

        industry.caSignWriteOff(param, '1.0').done(function (data) {
            console.log(data)
            if (data == undefined || data == null) {
                alert('参数未定义,请检查!');
            } else {
                alert(JSON.stringify(data));
            }
        }).fail(function (data) {
            console.log(data)
        });
    }

    //已换开作废
    function cancelpbillCASign() {
        var param = {
            "pBillBatchCode": "42811920",
            "pBillNo": "0090008409",
            "placeCode": "002",
            "author": "李四",
            "reason": "开错了",
            "busDateTime": "20210811144833032"
        }

        industry.cancelpbillCASign(param, '1.0').done(function (data) {
            console.log(data)
            if (data == undefined || data == null) {
                alert('参数未定义,请检查!');
            } else {
                alert(JSON.stringify(data));
            }
        }).fail(function (data) {
            console.log(data)
        });
    }

    function batchPrintElectBillSet(index) {
        var billNos = ["0000018510", "0000018511", "0000018512"];
        var billBatchCodes = ["448118191", "448118191", "448118191"];
        var randoms = ["b1273e1", "b1273e1", "b1273e1"];
        if (index >= billNos.length) {
            return;
        }
        var param = {
            'billBatchCode': billBatchCodes[index],
            'billNo': billNos[index],
            'random': randoms[index],
            'moduleId': '000000001'
        }
        industry.printElectBill(param, '1.0', false).then(function (data) {
            if (data && data.result != 'S0000') {
                alert(data.message)
            }
            console.log("success")
            batchPrintElectBillSet(index + 1);
        }).fail(function (data) {
            console.log(data)
        });
    }
</script>
</html>
